<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <%@ include file="/commons/basejs.jsp" %>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>储值卡管理</title>
    <style type="text/css">
        #edit_class_form tr{
            height: 40px;
        }
        #edit_class_form tr td{
            width: 100px;
            border: 1px solid #e0e0e0;
            padding-left: 5px;
        }
        #edit_card_form input,#edit_card_form select{
            width: 200px;
        }
        #choose_shop_dialog input{
            height: 20px;
            width: 190px;
            border-radius: 3px;
            top: 7px;
            left: 20px;
        }
        #loading {
             width:170px;
             height:25px;
             border:3px solid #C3DAF9;
             position:absolute;
             top:300px;
             left:600px;
             z-index:10000;
             background-color:#F7F9FC;
             line-height:25px;
             vertical-align:middle;
             font-size:11pt;
             display:none;
         }
    </style>
    <script src="../../../static/easyui/plugins/datagrid.show.js" type="text/javascript"></script>
</head>
<body>
<div id="loading"><img src="../../static/easyui/525478-20160801110927215-1304049696.gif" alt=""/>正在加载数据,请稍候...</div>
<div class="easyui-layout" fit="true" >
    <!--west分类列表start-->
    <div data-options="region:'west',split:true,border:false" title="分类列表" style="width:30%;">
        <table id="cardCategory_datagrid" class="easyui-datagrid"
               data-options="
		   		url:'${path}/card/cardClassdg.do',
		   		fit:true,
		   		rownumbers:true,
		   		fitColumns: true,
		   		toolbar:'#class_tools',
		   		pagination:true,
		   		singleSelect:true,
		   		onClickRow:function(index, row){
		   			getLabels(row.id);
		   		}">
            <thead>
            <th data-options="field:'id'">ID</th>
            <th data-options="field:'name',width:100">体检卡分类名称</th>
            <th data-options="field:'img',width:50,formatter:formatterImg">分类logo</th>
            <th data-options="field:'faceVal',width:50">面值</th>
            <th data-options="field:'totalRepertory',width:50">库存总数</th>
            <th data-options="field:'sell',width:50">已售数量</th>
            <th data-options="field:'remainRepertory',width:50">剩余数量</th>
            <th data-options="field:'actived',width:50">激活数量</th>
            <th data-options="field:'status',width:50,formatter:
            function(value){if(value==0) return '停用';return '可用';}">状态</th>
            </thead>
        </table>
        <div id="class_tools">
            <shiro:hasPermission name="/card/cardcatadd.do">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="openEditCardclassBox('add')">添加</a>
            </shiro:hasPermission>
            <shiro:hasPermission name="/card/cardcatedit.do">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit'" onclick="openEditCardclassBox('update')">修改</a>
            </shiro:hasPermission>
            <shiro:hasPermission name="/card/cardcatdelete.do">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove'" onclick="deleteCardclass()" >删除</a>
            </shiro:hasPermission>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-reload'" onclick="$('#cardCategory_datagrid').datagrid('reload')">刷新</a>
        </div>
    </div>

    <!--添加或修改体检卡种类弹窗-->
    <div class="easyui-dialog" id="edit_cardClass_dialog" title="添加体检卡种类" data-options="closed:true,modal:true,width:450,height:300">
        <form id="edit_class_form" method="post">
            <table align="center" style="margin-top: 20px">
                <input type="hidden" name="id" id="edit-id" />
                <tr style="border: 10px">
                    <td><lable for="name">种类名称:</lable></td>
                    <td><input class="easyui-validatebox" name="name" data-options="required:true" /></td>
                    <td rowspan="2"><img height="60px" src="" id="classimg"/></td>
                </tr>
                <tr >
                    <td><lable for="faceVal">面值:</lable></td>
                    <td><input class="easyui-validatebox" name="faceVal" data-options="required:true"/></td>
                </tr>
                <tr>
                    <td><lable for="img">图片:</lable></td>
                    <td><div id="upload_ue"></div><input class="easyui-validatebox" readonly="readonly" type="text" id="img"   data-options="required:true"  name="img"/></td>
                    <td><a href="javascript:void(0);"  class="easyui-linkbutton" data-options="iconCls:'icon-edit'" onclick="upImage();">上传图片</a></td>
                </tr>
                <tr >
                    <td><lable for="faceVal">可用状态:</lable></td>
                    <td colspan="2">
                    <span>禁用:</span><input class="easyui-validatebox" id="status0" name="status" type="radio" value="0" />
                    <span>可用:</span><input class="easyui-validatebox" id="status1" name="status" type="radio" value="1" checked/>
                </td>
                </tr>
                <tr >
                    <td><lable for="productId">线下套餐名称:</lable></td>
                    <td colspan="2"><select id="product" name="productId" style="width: 150px;"></select></td>
                </tr>
            </table>
            <div style="margin-top: 8px;text-align: center">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="editCardclass()">保存</a>
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="$('#edit_cardClass_dialog').dialog('close')">取消</a>
            </div>
        </form>
    </div>
            <script type="text/javascript">
                //联动处理classifyID处理Label
                function getLabels(classifyID) {
                    $("#card_datagrid").datagrid('clearSelections');
                    var queryParams = {};
                    queryParams.classId = classifyID;
                    //重新加载体检卡列表
                    var options = $("#card_datagrid").datagrid('getPager').data("pagination").options;
                    options.pageNumber = 1;
                    $("#card_datagrid").datagrid('options').queryParams = queryParams;
                    $("#card_datagrid").datagrid('reload');
                    //重新加载机构列表
                    var options2 = $("#shop_datagrid").datagrid('getPager').data("pagination").options;
                    options2.pageNumber = 1;
                    queryParams.flag=1;
                    $("#shop_datagrid").datagrid('options').queryParams = queryParams;
                    $("#shop_datagrid").datagrid('reload');
                    $("#sellerStatus").val(1);
                }
                //打开添加修改弹层
                function openEditCardclassBox(str) {
                    $("#edit_class_form").form("clear");
                    flag=str;
                    $("#product").combobox({
                        url : "${path}/card/productList.do",
                        valueField:'id',
                        textField:'name',
                        panelHeight : 'auto',
                        editable:false
                    });
                    if(str == "update"){
                        var select = $("#cardCategory_datagrid").datagrid("getSelected");
                        if(select == null){
                            $.messager.alert("提示","请选择一个体检卡种类","info");
                            return;
                        }
                        $("#edit_cardClass_dialog").dialog({title: "修改卡种类"});
                        $("#edit_class_form").form("load",select);
                        $("#classimg").attr("src",select.img);
                        $("#edit_cardClass_dialog").find("#status"+select.status).attr("checked","checked");
                    }else{
                        $("#classimg").attr("src","");
                        $("#edit_cardClass_dialog").find("#status1").attr("checked","checked");
                    }
                    $("#edit_cardClass_dialog").dialog("open");
                }
                var _editor;
                $(function() {
                    //重新实例化一个编辑器，防止在上面的editor编辑器中显示上传的图片或者文件
                    _editor = UE.getEditor('upload_ue',{
                        serverUrl:"${path}/file/upload.do?compress=1"
                    });
                    _editor.ready(function () {
                        //设置编辑器不可用
                        // _editor.setDisabled();
                        //隐藏编辑器，因为不会用到这个编辑器实例，所以要隐藏
                        _editor.hide();
                        //侦听图片上传
                        _editor.addListener('beforeInsertImage', function (t, arg) {
                            //有多少张图片arg.length就是多大
                            $("#img").val(arg[0].src);
                            $("#classimg").attr("src",arg[0].src);
                        });
                    });
                });
                //弹出图片上传的对话框
                function upImage() {
                    var myImage = _editor.getDialog("insertimage");
                    myImage.open();
                }
                //添加种类
                function editCardclass () {
                    $.messager.progress();
                    var url = "";
                    var str = "";
                    if(flag == 'add'){
                        url = "${path}/card/cardcatadd.do";
                        str = "添加";
                    }else if(flag == 'update'){
                        url = "${path}/card/cardcatedit.do";
                        str = "修改";
                    }
                    $("#edit_class_form").form("submit",{
                        url:url,
                        onSubmit:function(){
                            var valid = $(this).form("validate");
                            if (!valid) {
                                $.messager.progress("close");
                            }
                            return valid;
                        },
                        success:function(data){
                            data=$.parseJSON(data);
                            $.messager.progress("close");
                                if(data.success){
                                $("#edit_cardClass_dialog").dialog("close");
                                $.messager.show({
                                    title:str +"成功",msg:str +"成功!",
                                    timeout:600,style:"left:30%;top:10%",
                                    showType:"fade"
                                });
                                $("#cardCategory_datagrid").datagrid("reload");
                            }else{
                                $.messager.alert(str +"失败", data.msg,"error");
                            }
                        }
                    });
                }
                //删除卡种类
                function deleteCardclass() {
                    var select = $("#cardCategory_datagrid").datagrid("getSelected");
                    if(select == null){
                        $.messager.alert("提示","请选择一个种类","info");
                        return;
                    }
                    $.messager.confirm("确认","确定要删除该种类吗?\n确定删除将连同种类下的卡信息一同删除",function(yes){
                        if(yes){
                            commonDelete("${path}/card/cardcatdelete.do",select.id,"cardCategory_datagrid")
                        }
                    });
                }

            </script>
    <!--center体检卡列表start-->
    <div data-options="region:'center',split:true,border:false" title="体检卡列表" style="width:50%;">
        <table id="card_datagrid" class="easyui-datagrid"
               data-options="
		   		url:'${path}/card/carddg.do',
		   		rownumbers:true,
		   		fit:true,
		   		fitColumns: true,
		   		toolbar:'#card_tools',
		   		pagination:true,
		   		singleSelect:false">
            <thead>
            <th field="ck" checkbox="true"></th>
            <th data-options="field:'id'">ID</th>
            <th data-options="field:'store_card_category_id'" hidden="true">卡种类ID</th>
            <th data-options="field:'code',width:80">卡号</th>
            <th data-options="field:'pwd',width:50">密码</th>
            <th data-options="field:'face_val',width:50">面值</th>
            <th data-options="field:'receive_seller_id'" hidden="true">领取机构ID</th>
            <th data-options="field:'shopName',width:70">领取机构</th>
            <th data-options="field:'sales_channel',width:40,formatter:
            function(value){if(value==1) return '线下';if(value==0) return '线上';return '';}">销售渠道</th>
            <th data-options="field:'type',width:30,formatter:
            function(value){if(value==1)return '已售';if(value==2)return '激活';return '未售'}">状态</th>
            <th data-options="field:'user_id',width:50">购买人</th>
            <th data-options="field:'user_phone',width:50">购买人手机</th>
            <th data-options="field:'status',width:30,formatter:
            function(value){if(value) return '否';return '是';}">停用</th>
            </thead>
        </table>
        <div id="card_tools">
            <shiro:hasPermission name="/card/cardadd.do">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="openEditCardBox('add')">添加</a>
            </shiro:hasPermission>
            <shiro:hasPermission name="/card/uploadcard.do">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="openUploadCardBox('add')">批量添加</a>
            </shiro:hasPermission>
            <shiro:hasPermission name="/card/cardedit.do">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit'" onclick="openEditCardBox('update')">修改</a>
            </shiro:hasPermission>
            <shiro:hasPermission name="/card/carddelete.do">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove'" onclick="deleteCard()" >删除</a>
            </shiro:hasPermission>
            <shiro:hasPermission name="/card/cardshop.do">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove'" onclick="OpenCardshop()" >机构领取</a>
            </shiro:hasPermission>
            <shiro:hasPermission name="/card/cancelShop.do">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove'" onclick="Cancelshop()" >撤销领取</a>
            </shiro:hasPermission>
            <label>卡号:</label>
            <input class="easyui-searchbox" data-options="prompt:'请输入卡号',searcher:cardSearch" style="width:220px;"/>
            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-reload'" onclick="refcarddg()">刷新</a>
        </div>
</div>
    <!--添加修改体检卡-->
    <div class="easyui-dialog" id="edit_card_dialog" title="编辑体检卡" data-options="closed:true,modal:true,width:400,height:220">
        <form id="edit_card_form" method="post">
            <table align="center" style="margin-top: 20px">
                <input type="hidden" name="id" id="edit-cardid" />
                <tr>
                    <td><lable for="code">卡种类:</lable></td>
                    <td>
                        <select id="cardclass_id" class="easyui-combobox" data-options="panelHeight:'auto',required:true" name="storeCardCategoryId"  /></select>
                    </td>
                </tr>
                <tr>
                    <td><lable for="code">卡号:</lable></td>
                    <td><input class="easyui-validatebox" name="code" data-options="required:true" /></td>
                </tr>
                <tr >
                    <td><lable for="pwd">密码:</lable></td>
                    <td><input class="easyui-validatebox" name="pwd" data-options="required:true"/></td>
                </tr>
            </table>
            <div style="margin-top: 20px;text-align: center">
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="editCard()">保存</a>
                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" onclick="$('#edit_card_dialog').dialog('close')">取消</a>
            </div>
        </form>
    </div>
    <!--批量添加-->
    <div class="easyui-dialog" id="addcard_dialog" title="批量添加" data-options="closed:true,modal:true,width:360,height:140">
        <form id="uploadExcelForm"  method="post" enctype="multipart/form-data">
        <table align="center" class="addOrEditTable" style="width: 316px" >
            <tr>
                <td class="toright_td" width="100px"><span style="color:red">* </span>储值卡分类:</td>
                <td class="toleft_td" width="200px">&nbsp;&nbsp;
                    <select id="selcardcat1" class="easyui-validatebox easyui-combobox" style="width: 150px;" data-options="panelHeight:'auto',required:true" name="cardcatId"  /></select>
                </td>
            </tr>
            <tr>
                <td class="toright_td" width="100px" ><span style="color:red">* </span>Excel文件:</td>
                <td class="toleft_td" width="200px" >&nbsp;&nbsp;
                    <input id="excelId"  type="file" name="excelFile" >
                </td>
            </tr>
        </table>
        <div class="editButton"  data-options="region:'south',border:true" style="text-align: center; position: relative;top: 12px;" >
            <a class="easyui-linkbutton" icon="icon-save"  href="javascript:chaeckExcel();">保存</a>
        </div>
        </form>
    </div>
    <!--机构领取弹窗-->
    <div class="easyui-dialog" id="choose_shop_dialog" title="选择领取机构" data-options="closed:true,modal:true,width:400,height:70">
        <input type="hidden" id="cardids">
        <div style="position: relative;display: inline;">
            <input type="text" name="country" id="country" value="" hidden/>
            <input type="text" id="autocomplete-ajax" style="position: absolute; z-index: 2; background: transparent;"/>
            <input type="text" id="autocomplete-ajax-x" disabled="disabled" style="color: #CCC; position: absolute; background: transparent; z-index: 1;"/>
        </div>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="chooseShop()" style="position: absolute;right: 16px;top: 32px;">确定</a>
    </div>
    <script>
        var flag="add";
        function formatterImg(value){
            if(value!=null){
                return '<img height="40px"  src="'+value+'" alt="" />';
            }else{
                return '';
            }
        }
        //刷新体检卡列表
        function refcarddg(){
            var queryParams = {};
            queryParams.keyWord = "";
            var options = $("#card_datagrid").datagrid('getPager').data("pagination").options;
            options.pageNumber = 1;
            $("#card_datagrid").datagrid('options').queryParams = queryParams;
            $('#card_datagrid').datagrid('reload');
        }
        //查询体检卡
        function cardSearch(val) {
            var queryParams = {};
            if(val.length > 0){
                queryParams.keyWord = val;
            }
            var options = $("#card_datagrid").datagrid('getPager').data("pagination").options;
            options.pageNumber = 1;
            //重新加载
            $("#card_datagrid").datagrid('options').queryParams = queryParams;
            $("#card_datagrid").datagrid('reload');
        }
        //打开批量添加弹窗
        function openUploadCardBox(){
            $("#selcardcat1").val("");
            $("#excelId").val("");
            $('#selcardcat1').combobox({
                url : "${path}/card/getcardclass.do",
                valueField:'id',
                textField:'name',
                panelHeight : 'auto',
                editable:false
            });
            $("#addcard_dialog").dialog("open");
        }
        //打开体检卡编辑弹层
        function openEditCardBox(str) {
            $("#edit_card_form").form("clear");
            $('#cardclass_id').combobox({
                url : "${path}/card/getcardclass.do",
                valueField:'id',
                textField:'name',
                panelHeight : 'auto',
                editable:false
            });
            flag=str;
            if(str == "update"){
                var select = $("#card_datagrid").datagrid("getSelected");
                if(select == null){
                    $.messager.alert("提示","请选择一张体检卡","info");
                    return;
                }
                console.log(select);
                $("#edit_card_dialog").dialog({title: "修改体检卡"});
                $("#edit_card_form").form("load",select);
                $("#edit_card_form").find("[name='storeCardCategoryId']").val(select.store_card_category_id);
            }
            $("#edit_card_dialog").dialog("open");
        }
        //保存卡信息
        function editCard(){
            $.messager.progress();
            var url = "";
            var str = "";
            if(flag == 'add'){
                url = "${path}/card/cardadd.do";
                str = "添加";
            }else if(flag == 'update'){
                url = "${path}/card/cardedit.do";
                str = "修改";
            }
            $("#edit_card_form").form("submit",{
                url:url,
                onSubmit:function(){
                    var valid = $(this).form("validate");
                    if (!valid) {
                        $.messager.progress("close");
                    }
                    return valid;
                },
                success:function(data){
                    data=$.parseJSON(data);
                    $.messager.progress("close");
                    if(data.success){
                        $("#edit_card_dialog").dialog("close");
                        $.messager.show({
                            title:str +"成功",msg:str +"成功!",
                            timeout:600,style:"left:30%;top:10%",
                            showType:"fade"
                        });
                        $("#card_datagrid").datagrid("reload");
                    }else{
                        $.messager.alert(str +"失败", data.msg,"error");
                    }
                }
            });
        }
        //上传excel
        function  chaeckExcel() {
            var fileName = $("#excelId").val();
            if(fileName==""){
                $.messager.alert("提示","请上传excel文件~","error");
                return;
            }
           var option = {
               type: "POST",dataType: "JSON",
                url : "/card/uploadStoreCard.do",
               async : false,
                onSubmit:function(){
                    var valid = $(this).form("validate");
                    if (!valid) {
                        $.messager.alert("提示","请选择卡种类","error");
                    }
                    return valid;
                },
               beforeSend: function () {
                   $("#loading").show();
               },
               complete: function () {
                   $("#loading").hide();
               },
                success : function(data) {
                    data = JSON.parse(data);
                    if(data.success){
                        $.messager.alert("提示","添加成功","info");
                        $("#addcard_dialog").dialog("close");
                        $("#card_datagrid").datagrid("clearSelections");
                        $("#card_datagrid").datagrid("reload");
                    }else{
                        $.messager.alert("提示",data.msg,"error");
                    }
                },
               error:function(data){
                   $.messager.alert("提示",data.msg,"error");
               }
            };
           $("#uploadExcelForm").form("submit",option);
        }
        //打开机构领取弹层
        function OpenCardshop(){
            var selRows = $('#card_datagrid').datagrid('getChecked');
            if(selRows.length==0){$.messager.alert("提示","请勾选体检卡","info");return;}
            var cardids = "";
            for(var i=0;i<selRows.length;i++){
                cardids+=selRows[i].id+",";
            }
            $("#cardids").val(cardids.substring(0,cardids.length-1));
            //注册自动补全
            $('#autocomplete-ajax').autocomplete({
                serviceUrl: '${path}/card/autoCompleteData.do',
                onSelect: function(suggestion) {
                    $('#country').val(suggestion.data);
               },
                onHint: function (hint) {
                    $('#autocomplete-ajax-x').val(hint);
               }
            });
            $("#choose_shop_dialog").dialog("open");
        }
        //机构领取确定
        function chooseShop(){
            var cardids = $("#cardids").val();
            var shopId = $("#country").val();
            if(shopId=="")return;
            $.ajax({
                type: "POST",dataType: "JSON",
                url:"/card/editshopcards.do",
                data: {cardids:cardids,shopId:shopId},
                async : false,
                success: function(data){
                    if(data.success){
                        $("#choose_shop_dialog").dialog("close");
                        $.messager.show({
                            title:"成功",msg:"机构领取成功!",
                            timeout:600,style:"left:30%;top:10%",
                            showType:"fade"
                        });
                        $("#card_datagrid").datagrid("reload");
                    }else{
                        $.messager.alert("失败", data.msg,"error");
                    }
                }
            });
        }
        //撤销领取
        function Cancelshop() {
            var select = $("#card_datagrid").datagrid("getSelected");
            if(select == null){
                $.messager.alert("提示","请选择一张体检卡","info");
                return;
            }
            console.log(select.type);
            if(!select.type==0){
                $.messager.alert("提示","无法撤销已售体检卡","warning");
            }else{
                $.ajax({
                    type:"post",dataType:"json",
                   url: "/card/cancelShop.do",
                    data:{id:select.id},
                    success:function(data){
                        if(data.success){
                            $('#card_datagrid').datagrid('reload');
                            $.messager.alert("提示","撤销成功","info");
                        }else{
                            $.messager.alert("提示","撤销失败","error");
                        }
                    }
                });
            }
        }
        //删除体检卡
        function deleteCard(){
            var select = $("#card_datagrid").datagrid("getSelected");
            if(select == null){
                $.messager.alert("提示","请选择一张体检卡","info");
                return;
            }
            $.messager.confirm("确认","确定要删除该卡吗?\n确定删除将连同卡信息一同删除",function(yes){
                if(yes){
                    commonDelete("${path}/card/carddelete.do",select.id,"card_datagrid")
                }
            });
        }
        //删除公共调用方法
        function commonDelete(url,id,datagrid){
            $.messager.progress();
            $.ajax({
                url:url,
                type:"post",
                data:{id : id},
                dataType:"json",
                success:function(data){
                    $.messager.progress("close");
                    if(data.success){
                        $.messager.show({
                            title:"删除成功",
                            msg:"删除成功!",
                            timeout:600,
                            style:"left:30%;top:10%",
                            showType:"fade"
                        });
                        $("#"+datagrid).datagrid("reload");
                        $("#"+datagrid).datagrid('clearSelections');
                    }else{
                        $.messager.alert("删除失败", data.msg,"error");
                    }
                },
                error:function(){
                    $.messager.progress("close");
                    $.messager.alert("删除失败", "服务器连接失败!","error");
                }
            });
        }
    </script>

    <!--east机构列表start-->
    <div data-options="region:'east',split:true,border:false" title="支持消费机构" style="width:20%;">
        <table id="shop_datagrid" class="easyui-datagrid"
               data-options="
		   		url:'${path}/card/selectShops.do',
		   		rownumbers:true,
		   		fit:true,
		   		fitColumns: true,
		   		toolbar:'#shop_tools',
		   		pagination:true,
		   		singleSelect:true">
            <thead>
            <th data-options="field:'name',width:80">机构名称</th>
            <th data-options="field:'id',formatter:formatedit">操作</th>
            </thead>
        </table>
        <div id="shop_tools">
            <select id="sellerStatus" style="width:80px;position: relative;top: 3px;border-radius: 3px;" onchange="comboxchange()">
                <option value="1">支持消费</option>
                <option value="2">不支持消费</option>
            </select>
            <input id="searchshop" class="easyui-searchbox" data-options="prompt:'请输入机构',searcher:shopSearch" style="width:180px;"/>
        </div>
    </div>
    <script type="text/javascript">
        //操作单元格
        function formatedit(val,row){
            var datatype = $("#sellerStatus").val();
            if(datatype == 1){//可删除
                return '<a href="javascript:void(0)" class="configManage-easyui-linkbutton-del" onclick="editshop('+val+','+datatype+');" >删除</a>';
            }else{//可添加
                return '<a href="javascript:void(0)" class="configManage-easyui-linkbutton-add" onclick="editshop('+val+','+datatype+');" >添加</a>';
            }
        }
        //搜索机构
        function shopSearch() {
            var cardclassrow = $('#cardCategory_datagrid').datagrid('getSelected');
            if(cardclassrow==null){$.messager.alert("提示","未选择卡分类","error");return;}
            var type = $("#sellerStatus").val();
            var keyword = $("#searchshop").val();
            var queryParams = {};
            queryParams.classId = cardclassrow.id;
            queryParams.flag=type;
            queryParams.keyWord=keyword;
            var options = $("#shop_datagrid").datagrid('getPager').data("pagination").options;
            options.pageNumber = 1;
            $("#shop_datagrid").datagrid('options').queryParams = queryParams;
            $("#shop_datagrid").datagrid('reload');
        }
        //切换机构
        function comboxchange(){
            var type = $("#sellerStatus").val();
            var carccatrow = $('#cardCategory_datagrid').datagrid('getSelected');
            if(carccatrow==null){$.messager.alert("提示","未选择卡分类","error");return;}
            var queryParams = {};
            queryParams.classId = carccatrow.id;
            queryParams.flag=type;
            var options = $("#shop_datagrid").datagrid('getPager').data("pagination").options;
            options.pageNumber = 1;
            $("#shop_datagrid").datagrid('options').queryParams = queryParams;
            $("#shop_datagrid").datagrid('reload');
        }
        //添加支持机构
        function editshop(shopId,type){
            var classrow = $("#cardCategory_datagrid").datagrid('getSelected');
            $.ajax({
                type: "POST",dataType: "JSON",
                url:"/card/chooseshop.do",
                data: {classId:classrow.id,type:type,shopId:shopId},
                async : false,
                success: function(data){
                    console.log(data);
                    shopSearch();
                }
            });
        }
    </script>
</div>
</body>
</html>
